// $Id: io_w.cpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#include <sstream>
#include <boost/test/unit_test.hpp>
#include <xpcom/uuid.hpp>
#include <xpcom/string.hpp>

#ifdef XPCOM_HAS_2BYTE_WCHAR_T
#ifndef BOOST_NO_STD_WSTRING

BOOST_AUTO_TEST_CASE(test_extract_w)
{
    using namespace xpcom;

    // Parse success
    uuid id1 = { 0x64D47515, 0xADE3, 0x45d1,
            { 0xAB, 0xAE, 0x3A, 0x93, 0x62, 0xC5, 0xA5, 0x51 } };
    uuid id2;
    uuid id3;

    std::wstringstream id_str1(L"  {64D47515-ADE3-45d1-ABAE-3A9362C5A551}XYZ     64D47515-ADE3-45d1-abae-3A9362C5A551 ");
    std::wstringstream id_str2(L"{64D47515-ADE3-45d1-ABAE-3A62C5A551}");
    std::wstringstream id_str3(L"  64D47515-ADE3-45d1-ABAE-3A62C5A551  ");
    std::wstringstream id_str4(L" {64D47515-ADE3-45d1-ABAE-3A9362C5A551XYZ");
    std::wstringstream id_str5;
    std::wstringstream id_str6(L"64D470515-ADE3-45d1-abae-3a9362c5a551XYZ");
    std::wstringstream id_str7(L"64D47S15-ADE3-45d1-abae-3a9362c5a551XYZ");

    id_str1 >> id2 >> id3;
    BOOST_CHECK(id1 == id2);
    BOOST_CHECK(id1 == id3);

    id2 = uuid::nil;
    id_str2 >> id2;
    BOOST_CHECK(!id_str2);

    id2 = uuid::nil;
    id_str3 >> id2;
    BOOST_CHECK(!id_str3);

    id2 = uuid::nil;
    id_str4 >> id2;
    BOOST_CHECK(!id_str4);

    id2 = uuid::nil;
    id_str5 >> id2;
    BOOST_CHECK(!id_str5);

    id2 = uuid::nil;
    id_str6 >> id2;
    BOOST_CHECK(!id_str6);

    // TODO Bad hex digit
    id2 = uuid::nil;
    id_str7 >> id2;
#if 0
    BOOST_CHECK(!id_str7);
#endif
    BOOST_CHECK(id_str7);
    BOOST_CHECK(id1 != id2);
}

BOOST_AUTO_TEST_CASE(test_insert_w)
{
    using namespace xpcom;

    // Parse success
    uuid id = { 0x64D47515, 0xADE3, 0xa5d1,
            { 0xAB, 0xAE, 0x3A, 0x93, 0x62, 0xC5, 0xA5, 0x51 } };

    std::wstringstream s;
    s << id;
    BOOST_CHECK(s);
    BOOST_CHECK(s.str() == L"64D47515-ADE3-a5d1-ABAE-3A9362C5A551");
}

#endif
#endif
